﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

using Afvanding.RefToPumpService;

namespace Afvanding
{
    /// <summary>
    /// Interaction logic for NewStationWindow.xaml
    /// </summary>
    public partial class NewStationWindow : Window
    {
        private PumpServiceClient _pumpService;

        public NewStationWindow()
        {
            InitializeComponent();

            _pumpService = new PumpServiceClient();
        }

        private void btnAddNewStation_Click(object sender, RoutedEventArgs e)
        {
            int port;
            double waterLevel;

            if (int.TryParse(txtPort.Text, out port) &&
                double.TryParse(txtWaterLevel.Text, out waterLevel))
            {
                string ip = txtIPaddress.Text;

                int status = int.MinValue;
                if (cbStatus.Text == "Running")
                    status = 1;
                else if (cbStatus.Text == "Stopped")
                    status = 0;

                bool add = _pumpService.AddStation(ip, port, waterLevel, status);
                MessageBox.Show(add ? "tilføjet" : "ikke tilføjet");
            }
            else
                MessageBox.Show("Der skete en fejl");
        }
    }
}